/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor. ПроверкаЫ
 */
SrcsoftSpoiler = {
  version: '1.0.0.56',
  author: 'sedegoff.com',
  options: {
    parentId: "Blog1", //ID Элемента, внутри которого будет осуществлён поиск спойлеров
    spoiler: "srcsoft-spoiler", //Наименованиме класса спойлера
    hidden: "srcsoft-spoiler-hidden", //
    visible: "srcsoft-spoiler-visible",
    caption: "srcsoft-spoiler-caption",
    text: "srcsoft-spoiler-text",
    tm: "srcsoft-spoiler-copy",
    image: "srcsoft-spoiler-img",
    captionText: "Спойлер", 
    Document: "spoiler.js",
    CreatedOn: "15.04.2011, 17:16:25",
    Author: "Седегов Е.В.",
    Description: "Скрипт для спойлера www.sedegoff.com"
  },
  set: function (option, value){
    if (this.options[option] != undefined){this.options[option] = value;}
  },
  getElementsByClassName: function (classname, node){
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
      if(re.test(els[i].className))a.push(els[i]);
    return a;
  },
  OnClickSpoiler: function (elem){
    var parent = elem.parentNode;
    if (parent.className == this.options.hidden){
      parent.className = this.options.visible;
      return;
    }
    parent.className = this.options.hidden;
  },
  init: function AddSpoilerHandler(){
    var parentNode = document.getElementById(this.options.parentId);
    var spoilers = this.getElementsByClassName(this.options.spoiler, parentNode);
    for(var i=0,j=spoilers.length; i<j; i++){
      spoilers[i].className = "srcsoft-spoiler-hidden";
      var div1 = document.createElement("div");
      var div2 = document.createElement("div");
      var div3 = document.createElement("div");
      var p1 = document.createElement("div");
      var a1 = document.createElement("a");
      var br1 = document.createElement("br");
      div1.className = this.options.caption;
      div1.innerHTML = spoilers[i].getAttribute("title") ? spoilers[i].getAttribute("title") : this.options.captionText;
      div1.onclick = function(){SrcsoftSpoiler.OnClickSpoiler(this)}
      spoilers[i].removeAttribute("title");
      div2.className = this.options.text;
      div2.innerHTML = spoilers[i].innerHTML;
      div2.appendChild(br1);
      p1.className = this.options.tm;
      p1.innerHTML = "spoiler by ";
      a1.setAttribute("href", "http://www.sedegoff.com");
      a1.innerHTML = "Sedegoff";
      div3.className = this.options.image;
      div3.onclick = function(){SrcsoftSpoiler.OnClickSpoiler(this)}
      p1.appendChild(a1);
      div2.appendChild(p1);
      spoilers[i].innerHTML = "";
      spoilers[i].appendChild(div3);
      spoilers[i].appendChild(div1);
      spoilers[i].appendChild(div2);
    }
  }
};

